﻿Namespace InterfaceBar

    Module mInterfaceBar

        Public WithEvents MainInterfaceBarWin As GUI.MirWindow

        Public WithEvents MainInterfaceBarEquipmentButton As GUI.MirButton
        Public WithEvents MainInterfaceBarInventoryButton As GUI.MirButton
        Public WithEvents MainInterfaceBarSpellBookButton As GUI.MirButton
        Public WithEvents MainInterfaceBarTradeButton As GUI.MirButton
        Public WithEvents MainInterfaceBarBeltButton As GUI.MirButton
        Public WithEvents MainInterfaceBarMiniMapButton As GUI.MirButton
        Public WithEvents MainInterfaceBarQuestBookButton As GUI.MirButton
        Public WithEvents MainInterfaceBarOptionsButton As GUI.MirButton


        Public WithEvents AvatarInterfaceWin As GUI.MirWindow

        Public WithEvents AvatarCompact As GUI.MirButton
        Public WithEvents AvatarFull As GUI.MirButton
        Private AvatarState As Byte

        Public AvatarLib As EvoLib.Protocol.ImgLibs
        Public AvatarImg As Integer = -1

        Public IsShowingExpToolTip As Boolean

        Public Sub Init()

            Dim x As Integer, y As Integer, w As Integer, h As Integer

            x = 0
            y = Constants.gGameResY - Libs.GameInter.Image(69).Header.Height
            w = 94
            h = Libs.GameInter.Image(69).Header.Height

            AvatarInterfaceWin = New GUI.MirWindow("AvatarInterfaceWin", x, y, w, h)

            y = Constants.gGameResY - Libs.GameInter.Image(51).Header.Height
            x = 94
            w = Libs.GameInter.Image(51).Header.Width
            h = Libs.GameInter.Image(51).Header.Height

            MainInterfaceBarWin = New GUI.MirWindow("MainInterfaceBarWin", x, y, w, h)

            MainInterfaceBarEquipmentButton = New GUI.MirButton(MainInterfaceBarWin, "EquipmentButton", 430, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 81, 82, "\0Equipment", False)
            MainInterfaceBarInventoryButton = New GUI.MirButton(MainInterfaceBarWin, "InventoryButton", 464, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 83, 84, "Inventory", False)
            MainInterfaceBarSpellBookButton = New GUI.MirButton(MainInterfaceBarWin, "SpellBookButton", 498, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 85, 86, "Spell Book", False)
            MainInterfaceBarTradeButton = New GUI.MirButton(MainInterfaceBarWin, "TradeButton", 532, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 95, 96, "Initiate Trade", False)
            MainInterfaceBarBeltButton = New GUI.MirButton(MainInterfaceBarWin, "BeltButton", 566, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 87, 88, "Belt", False)
            MainInterfaceBarMiniMapButton = New GUI.MirButton(MainInterfaceBarWin, "MiniMapButton", 600, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 89, 90, "Toggle MiniMap", False)
            MainInterfaceBarQuestBookButton = New GUI.MirButton(MainInterfaceBarWin, "QuestBookButton", 634, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 91, 92, "Quest Book", False)
            MainInterfaceBarOptionsButton = New GUI.MirButton(MainInterfaceBarWin, "OptionsButton", 668, 16, 0.01, EvoLib.Protocol.ImgLibs.GameInter, 0, 93, 94, "Options", False)


            AvatarCompact = New GUI.MirButton(AvatarInterfaceWin, "AvatarCompact", 0, 0, 0, EvoLib.Protocol.ImgLibs.GameInter, 69, , , , False)
            AvatarFull = New GUI.MirButton(AvatarInterfaceWin, "AvatarFull", 0, 0, 0, EvoLib.Protocol.ImgLibs.GameInter, 68, , , , False)
            AvatarFull.Visible = False

            Windows.AddWindow(MainInterfaceBarWin, Windows.WindowType.AlwaysOnTop)
            Windows.AddWindow(AvatarInterfaceWin, Windows.WindowType.AlwaysOnTop)

        End Sub

        Public Sub Shutdown()
            MainInterfaceBarWin.Destory()
            AvatarInterfaceWin.Destory()
        End Sub

        Private Sub MainInterfaceBarWin_DrawWindow(ByRef mode As Globals.DrawingMode, ByRef x As Integer, ByRef y As Integer, ByRef z As Single) Handles MainInterfaceBarWin.DrawWindow

            If mode = Globals.DrawingMode.Normal Then

                Libs.GameInter.Image(51).Draw(x, y, z)

                'Libs.GameInter.Image(53).Draw(x + 17, y + 17, z)

                With Libs.GameInter.Image(55)
                    If Player.VitalPoints.MAXMP > 0 Then
                        DirectX.BlitD3D(.Texture, x + 17, y + 33, .Header.Width * (Player.VitalPoints.MP / Player.VitalPoints.MAXMP), .Header.Height, z)
                    End If
                End With

                With Libs.GameInter.Image(53)
                    If Player.VitalPoints.MAXHP > 0 Then
                        DirectX.BlitD3D(.Texture, x + 17, y + 17, .Header.Width * (Player.VitalPoints.HP / Player.VitalPoints.MAXHP), .Header.Height, z)
                    End If
                End With

                'exp bar

                Dim xp As Single = (Player.CurrentXP / Player.NextLevelXP) * 10
                Dim xoff As Integer

                Do Until xp < 0.0F

                    If xp > 1.0F Then
                        Libs.GameInter.Image(57).Draw(x + 2 + xoff, y + 5, z)
                    Else
                        With Libs.GameInter.Image(57)
                            DirectX.BlitD3D(.Texture, x + 2 + xoff, y + 5, .Header.Width * xp, .Header.Height, z)
                        End With
                    End If

                    xoff += 70

                    xp -= 1.0F

                Loop

                'weight
                If Player.Stats.INT2_MAX_WEIGHT > 0 Then
                    Dim weight As Single = Player.PlayerWeight.INT4_BAGWEIGHT / Player.Stats.INT2_MAX_WEIGHT

                    If weight > 0.0F Then
                        If weight > 1.0F Then
                            Libs.GameInter.Image(61).Draw(x + 7, y + 16, z)
                        Else
                            With Libs.GameInter.Image(61)
                                DirectX.BlitD3D(.Texture, x + 7, y + 16 + (.Header.Height - Int(.Header.Height * weight)), .Header.Width, Int(.Header.Height * weight), z)
                            End With
                        End If
                    End If
                End If

                ElseIf mode = Globals.DrawingMode.Text Then

                    DirectX.ProFont9.DrawBoldBorderText(Player.VitalPoints.HP & " / " & Player.VitalPoints.MAXHP, x + (107 - (DirectX.ProFont9.GetBoldTextWidth(Player.VitalPoints.HP & " / " & Player.VitalPoints.MAXHP) / 2)), y + 18, Color.White, Color.Black, z)
                    DirectX.ProFont9.DrawBoldBorderText(Player.VitalPoints.MP & " / " & Player.VitalPoints.MAXMP, x + (107 - (DirectX.ProFont9.GetBoldTextWidth(Player.VitalPoints.MP & " / " & Player.VitalPoints.MAXMP) / 2)), y + 34, Color.White, Color.Black, z)


                    '235,17 Class
                    Select Case Player.PlayerJob
                        Case EvoLib.Protocol.CharacterJobs.Warrior
                            DirectX.ProFont9.DrawNormalText("War", x + 235, y + 17, Color.White, z)
                        Case EvoLib.Protocol.CharacterJobs.Sorcerer
                            DirectX.ProFont9.DrawNormalText("Wiz", x + 235, y + 17, Color.White, z)
                        Case EvoLib.Protocol.CharacterJobs.Taoist
                            DirectX.ProFont9.DrawNormalText("Tao", x + 235, y + 17, Color.White, z)
                    End Select

                    '235,34 Level
                    DirectX.ProFont9.DrawNormalText(Player.PlayerLevel, x + 235, y + 34, Color.White, z)

                    DirectX.ProFont9.DrawNormalText(Player.FamePoints, x + 303, y + 17, Color.White, z)
                    DirectX.ProFont9.DrawNormalText(Player.Stats.INT2_MIN_DC & "-" & Player.Stats.INT2_MAX_DC, x + 303, y + 34, Color.White, z)

                    '370 
                    DirectX.ProFont9.DrawNormalText(Player.Stats.INT2_MIN_AC & "-" & Player.Stats.INT2_MAX_AC, x + 370, y + 17, Color.White, z)
                    DirectX.ProFont9.DrawNormalText(Player.Stats.INT2_MIN_MAC & "-" & Player.Stats.INT2_MAX_MAC, x + 370, y + 34, Color.White, z)

                End If

        End Sub

        Private Sub AvatarInterfaceWin_DrawWindow(ByRef mode As Globals.DrawingMode, ByRef x As Integer, ByRef y As Integer, ByRef z As Single) Handles AvatarInterfaceWin.DrawWindow

            If mode = Globals.DrawingMode.Normal Then

                If AvatarState = 0 Or AvatarState = 3 Then
                ElseIf AvatarState = 1 Then
                    AvatarInterfaceWin.SetSize(94, Libs.GameInter.Image(69).Header.Height + (Timers.GetTimer("AvatarMovement") * 4))
                    AvatarInterfaceWin.SetPosition(0, Constants.gGameResY - Libs.GameInter.Image(69).Header.Height - (Timers.GetTimer("AvatarMovement") * 4))
                    y = Constants.gGameResY - Libs.GameInter.Image(69).Header.Height - (Timers.GetTimer("AvatarMovement") * 4)
                    If Timers.GetTimer("AvatarMovement") = Int((Libs.GameInter.Image(68).Header.Height - Libs.GameInter.Image(69).Header.Height) / 4) Then
                        AvatarState = 3
                        Timers.RemoveTimer("AvatarMovement")
                    End If
                Else
                    AvatarInterfaceWin.SetSize(94, Libs.GameInter.Image(68).Header.Height - (Timers.GetTimer("AvatarMovement") * 4))
                    AvatarInterfaceWin.SetPosition(0, Constants.gGameResY - Libs.GameInter.Image(68).Header.Height + (Timers.GetTimer("AvatarMovement") * 4))
                    y = Constants.gGameResY - Libs.GameInter.Image(68).Header.Height + (Timers.GetTimer("AvatarMovement") * 4)
                    If Timers.GetTimer("AvatarMovement") = Int((Libs.GameInter.Image(68).Header.Height - Libs.GameInter.Image(69).Header.Height) / 4) Then
                        AvatarState = 0
                        Timers.RemoveTimer("AvatarMovement")
                        AvatarCompact.Visible = True
                        AvatarFull.Visible = False
                        AvatarInterfaceWin.SetPosition(0, Constants.gGameResY - Libs.GameInter.Image(69).Header.Height)
                        AvatarInterfaceWin.SetSize(94, Libs.GameInter.Image(69).Header.Height)
                    End If
                End If

                If AvatarState = 0 Then
                    Libs.GameInter.Image(72).Draw(x + 6, y + 42, z)
                Else
                    If AvatarImg = -1 Then
                        Libs.GameInter.Image(71).Draw(x + 6, y + 42, z)
                    Else
                        Libs.GetLib(AvatarLib).Image(AvatarImg).Draw(x + 6, y + 42, z)
                    End If
                End If

            End If

        End Sub

        Private Sub AvatarCompact_Click() Handles AvatarCompact.Click

            AvatarState = 1
            AvatarCompact.Visible = False
            AvatarFull.Visible = True

            Timers.AddTimer("AvatarMovement", 25, (Libs.GameInter.Image(68).Header.Height - Libs.GameInter.Image(69).Header.Height) / 4, True)

        End Sub

        Private Sub AvatarFull_Click() Handles AvatarFull.Click

            If AvatarState = 3 Then

                AvatarState = 2
                Timers.AddTimer("AvatarMovement", 25, (Libs.GameInter.Image(68).Header.Height - Libs.GameInter.Image(69).Header.Height) / 4, True)

            End If

        End Sub

        Private Sub MainInterfaceBarWin_MouseEvent(ByRef type As Mouse.mMouseVars.MouseInputType, ByRef e As System.Windows.Forms.MouseEventArgs) Handles MainInterfaceBarWin.MouseEvent
            'Game.PlayerInputMouseCheck(type, e)

            GameWindow.MousePointX = e.X
            GameWindow.MousePointY = e.Y

            If e.X <= 704 And e.Y >= 3 And e.Y <= 12 Then
                IsShowingExpToolTip = True
                GameWindow.SetTooltip("Exp: " & FormatPercent(Player.CurrentXP / Player.NextLevelXP), 0)
            Else
                IsShowingExpToolTip = False
            End If

            If Not IsShowingExpToolTip Then GameWindow.HideTooltip()

        End Sub

        Private Sub AvatarInterfaceWin_MouseEvent(ByRef type As Mouse.mMouseVars.MouseInputType, ByRef e As System.Windows.Forms.MouseEventArgs) Handles AvatarInterfaceWin.MouseEvent
            'Game.PlayerInputMouseCheck(type, e)
        End Sub

        Private Sub MainInterfaceBarEquipmentButton_Click() Handles MainInterfaceBarEquipmentButton.Click
            Equipment.ToggleEquipmentWindow()
        End Sub

        Private Sub MainInterfaceBarInventoryButton_Click() Handles MainInterfaceBarInventoryButton.Click
            Inventory.ToggleInventoryWindow()
        End Sub

        Private Sub MainInterfaceBarEquipmentButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarEquipmentButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarInventoryButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarInventoryButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarBeltButton_Click() Handles MainInterfaceBarBeltButton.Click
            Belt.Toggle()
        End Sub

        Private Sub MainInterfaceBarBeltButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarBeltButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarMiniMapButton_Click() Handles MainInterfaceBarMiniMapButton.Click
            MiniMap.Toggle()
        End Sub

        Private Sub MainInterfaceBarMiniMapButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarMiniMapButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarOptionsButton_Click() Handles MainInterfaceBarOptionsButton.Click
            GameMenu.ToggleShowMenu()
        End Sub

        Private Sub MainInterfaceBarOptionsButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarOptionsButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarQuestBookButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarQuestBookButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarSpellBookButton_Click() Handles MainInterfaceBarSpellBookButton.Click
            MagicWindow.ToggleSkillTree()
        End Sub

        Private Sub MainInterfaceBarSpellBookButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarSpellBookButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub

        Private Sub MainInterfaceBarTradeButton_RequestingTooltip(tttxt As String) Handles MainInterfaceBarTradeButton.RequestingTooltip
            GameWindow.SetTooltip(tttxt, 0, True)
        End Sub
    End Module

End Namespace

